/*
 * readingMeshReady.java
 *
 * Created on 20 de Abril de 2008, 01:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.cpqd.ssar.posprocessamento;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 *
 * @author igorj
 */
public class readingMeshReady {
    
    private CubeElement nCube;
    private Vector listCubeElements = new Vector();
    private FileInputStream is;                 // Stream de Entrada
    private BufferedReader br;                  // Buffer de leitura
    private char[] line = null;
    private String[] vline = null;
    private String s;
    
    private Double cor;
    
    /** Creates a new instance of readingMeshReady */
    public readingMeshReady() {
    }
    
    public Vector getMeshReady(String fileName) throws FileNotFoundException, IOException{
        
        /* neste caso, o arquivo de configura��o n�o tem cont�m a palavra chave 'malha'
         * portanto, trata-se de um arquivo que cont�m a malha da cabe�a humana (do Phantom)
         */
        
        is = new FileInputStream(fileName);
        br = new BufferedReader(new InputStreamReader(is));
        
         //while((s = br.readLine()) != null )
        for(int i=0; i<4388608; i++)  
        { 
            
            
            s = br.readLine();
            vline = split(s);
            //System.out.println(vline[3]);
            if(Integer.valueOf(vline[3]) != 0) {
                cor = Double.valueOf(vline[3]);
                cor = ((cor * 255)/124)/255;
                nCube = new CubeElement(Double.valueOf(vline[0]),Double.valueOf(vline[1]), Double.valueOf(vline[2]), cor);
                listCubeElements.add(nCube);
            }
            
        }
        System.out.println("malha pronta");
        return listCubeElements;
    }
    
    public String[] split(String sentence) {
        //vetor que contem x,y,z e campo
        
        String[] tokens = null;
        
        String splitPattern = " ";
        
        tokens = sentence.split(splitPattern);
        
        if (tokens == null) {
            String msg = "   NO MATCH: pattern:" + sentence
                    + "\r\n             regex: " + splitPattern;
        } else
            return tokens;
        
        return tokens;
        
    }
    
    
}


